package com.woniuxy.qiantai.consumer;

import com.rabbitmq.client.Channel;
import com.woniuxy.qiantai.config.SendSmsUtils;
import org.springframework.amqp.core.Message;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.redis.core.RedisTemplate;
import org.springframework.stereotype.Component;

import java.io.IOException;

@Component
public class VerificationConsumer {
    @Autowired
    RedisTemplate<String, String> stringRedisTemplate;

    @RabbitListener(queues = "verification")
    public void onMsg(String phoneNumber, Message message, Channel channel) throws IOException {
        SendSmsUtils.sendCode(phoneNumber, stringRedisTemplate);
        channel.basicAck(message.getMessageProperties().getDeliveryTag(),false);
    }

}
